<html><head><link href="../../../css-stylesheets/elucidator/program.css" rel="stylesheet" title="program" type="text/css" /> <title>Source file</title></head><body bgcolor="#ffffff" text="#000000" link="#000000" vlink="#000000"><font size="2"><pre><div class="schemedoc-abstract-comment">;;;; This library supports buffered input stream. A buffered input stream is convenient for various kinds of parsing tasks. &lt;p&gt;
;;;; It is assumed that the variable ip references an open input port, or a string. The assignment of ip must be done
;;;; exernally to this library, and after the library is loaded. If ip references an open input stream (made by the Scheme function
;;;; open-input-file, for instance) input is read from that port. If ip is string, the variable pstring-ip-pointer is used as a pointer
;;;; into the string.&lt;p&gt;
;;;; The functions in section one are generic, low-level reading functions that either read from the open input port, or from a string (at the location 
;;;; determined by the variable pstring-ip-pointer). The functions in section two are the basic reading and peeking functions. 
;;;; In section three a number of convenient collection and skipping functions
;;;; are provided for.&lt;p&gt;
;;;; This library has been developed as part of an SGML/XML Document Type Definition (DTD) parser, but
;;;; it is useful in many other parsing situations.
;;;; There exists &lt;a href="http://www.cs.auc.dk/~normark/scheme/tools/dtd-parser/doc/html/index.html"&gt;som early internal documentation&lt;/a&gt;
;;;; of the DTD parser (on the www.cs.auc.dk site)
;;;; and as such also of some aspects of the functions in this library.&lt;p&gt;
;;;; In earlier versions of LAML, this library was called 'the text collection and skipping library'.
;;;; .title Reference Manual of Buffered Input Streams</div>

<a name="ip"></a><span class="comment">; An open input port, or a string.</span><br /><a name="ip"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">ip</span> #f)

<a name="pstring-ip-pointer"></a><span class="comment">; Only used if we use a string type ip. Points at the char to be read next.</span><br /><a name="pstring-ip-pointer"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">pstring-ip-pointer</span> 0)<span class="comment">; </span><br /><span class="comment">; ========================================================================================================================</span><br /><div class="schemedoc-section-comment">;;; Low-level, generic input functions.
;;; The functions in this section reads from either an input port, or from a string.</div>
<a name="generic-read-char"></a><div class="schemedoc-definition-comment">;; Reads a single character from ip, and advances the input pointer.</div><a name="generic-read-char"></a><span><a href="../collect-skip.html#generic-read-char"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(generic-read-char ip)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX438" title="R5RS Scheme form">input-port?</a> ip) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX451" title="R5RS Scheme form">read-char</a> ip))
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX374" title="R5RS Scheme form">string?</a> ip) 
           (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX239" title="R5RS Scheme form">&gt;=</a> <a class="applied-name" href="collect-skip-1.html#pstring-ip-pointer" title="collect-skip">pstring-ip-pointer</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> ip))
               #f
               (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">res</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> ip <a class="applied-name" href="collect-skip-1.html#pstring-ip-pointer" title="collect-skip">pstring-ip-pointer</a>)))
		 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="collect-skip-1.html#pstring-ip-pointer" title="collect-skip">pstring-ip-pointer</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> 1 <a class="applied-name" href="collect-skip-1.html#pstring-ip-pointer" title="collect-skip">pstring-ip-pointer</a>))
		 res)))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="schemedoc-name" href="../../../lib/man/general.html#laml-error" title="Manual: general">laml-error</a> "generic-read-char: ip must be a string or an input stream"))))

<a name="generic-eof-object?"></a><div class="schemedoc-definition-comment">;; Is x the designated end-of-file value relative to the implicitly given input port ip.</div><a name="generic-eof-object?"></a><span><a href="../collect-skip.html#generic-eof-object?"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(generic-eof-object? x)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX438" title="R5RS Scheme form">input-port?</a> <a class="applied-name" href="collect-skip-1.html#ip" title="collect-skip">ip</a>) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX455" title="R5RS Scheme form">eof-object?</a> x))
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX374" title="R5RS Scheme form">string?</a> <a class="applied-name" href="collect-skip-1.html#ip" title="collect-skip">ip</a>) (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX305" title="R5RS Scheme form">boolean?</a> x) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> x)))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="schemedoc-name" href="../../../lib/man/general.html#laml-error" title="Manual: general">laml-error</a> "generic-eof-object?: ip must be a string or an input stream"))))

<a name="generic-at-eof?"></a><span class="comment">; A non functional eof condition. Works only for string ip's</span><br /><a name="generic-at-eof?"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(generic-at-eof?)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a>  ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX374" title="R5RS Scheme form">string?</a> <a class="applied-name" href="collect-skip-1.html#ip" title="collect-skip">ip</a>) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> <a class="applied-name" href="collect-skip-1.html#pstring-ip-pointer" title="collect-skip">pstring-ip-pointer</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> <a class="applied-name" href="collect-skip-1.html#ip" title="collect-skip">ip</a>)))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="schemedoc-name" href="../../../lib/man/general.html#laml-error" title="Manual: general">laml-error</a> "generic-at-eof?: ip must be a string for this function to work"))))
    


<span class="comment">; ========================================================================================================================</span><br />
<div class="schemedoc-section-comment">;;; Look ahead buffer and queue.
;;; The functions in this section manipulates a look ahead queue, which is in between the input port ip
;;; and the applications. Via this buffer it is possible to implement look ahead in the input port.&lt;p&gt;
;;; Imagine an input buffer of (actual) size n:
;;; &lt;pre&gt;    c1 c2 c3 ... cn &lt;/pre&gt;
;;; When characters are read from the input stream, they enter to the right (the peek end).
;;; When characters are read by an application they are taken from the left (the read end).
;;; Thus, cn is the last character read from the input port (or from the input string); This is done by peek-a-char.
;;; c1 is the next char to leave the buffer, and to be read by the client application; This will be done by read-a-char.&lt;p&gt;
;;;
;;;
;;; A few words about terminology in relation to R4RS or R5RS. The Scheme procedure read-char corresponds roughtly to read-a-char;
;;; The former always reads a character from an input port; The latter reads from an input stream via the buffer; 
;;; Only if the buffer is empty, a character is read from the port or string.
;;; The proper Scheme function peek-char returns the next char from the input port, without updating the 'input pointer'.
;;; The function peek-a-char of this library is different, because it reads a character from the file and puts it into the buffer.
;;; This use of terminology is unfortunate, and it may be confusing for some readers.</div>

<a name="max-look-ahead"></a><div class="schemedoc-definition-comment">;; The length of the cyclic look ahead buffer. Predefined to 20000 characters. A constant.</div><a name="max-look-ahead"></a><span><a href="../collect-skip.html#max-look-ahead"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">max-look-ahead</span> 20000)

<a name="look-ahead-vector"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">look-ahead-vector</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX400" title="R5RS Scheme form">make-vector</a> <a class="applied-name" href="collect-skip-1.html#max-look-ahead" title="collect-skip">max-look-ahead</a> #\space))
<a name="next-write"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">next-write</span> 0)
<a name="next-read"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">next-read</span> 0)
<a name="look-ahead-length"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">look-ahead-length</span> 0)

<a name="end-of-file?"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">end-of-file?</span> #f)

<a name="reset-look-ahead-buffer"></a><div class="schemedoc-definition-comment">;; Reset the look ahead buffer. 
;; You should always call this function after you have re-assigned ip to a new input stream.</div><a name="reset-look-ahead-buffer"></a><span><a href="../collect-skip.html#reset-look-ahead-buffer"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(reset-look-ahead-buffer)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="collect-skip-1.html#ip" title="collect-skip">ip</a> #f)
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="collect-skip-1.html#pstring-ip-pointer" title="collect-skip">pstring-ip-pointer</a> 0)
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="collect-skip-1.html#next-write" title="collect-skip">next-write</a> 0)
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="collect-skip-1.html#next-read" title="collect-skip">next-read</a> 0)
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="collect-skip-1.html#look-ahead-length" title="collect-skip">look-ahead-length</a> 0)
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="collect-skip-1.html#look-ahead-vector" title="collect-skip">look-ahead-vector</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX400" title="R5RS Scheme form">make-vector</a> <a class="applied-name" href="collect-skip-1.html#max-look-ahead" title="collect-skip">max-look-ahead</a> #\space))
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="collect-skip-1.html#end-of-file?" title="collect-skip">end-of-file?</a> #f)
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="collect-skip-1.html#collection-buffer" title="collect-skip">collection-buffer</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX375" title="R5RS Scheme form">make-string</a> <a class="applied-name" href="collect-skip-1.html#buffer-length" title="collect-skip">buffer-length</a> #\space))
)

<a name="get-look-ahead-buffer"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(get-look-ahead-buffer)</span>
  (<a class="schemedoc-name" href="../../../lib/man/general.html#pair-up" title="Manual: general">pair-up</a>
    '(ip pstring-ip-pointer next-write next-read look-ahead-length look-ahead-vector end-of-file? collection-buffer buffer-length)
    (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX332" title="R5RS Scheme form">list</a> <a class="applied-name" href="collect-skip-1.html#ip" title="collect-skip">ip</a> <a class="applied-name" href="collect-skip-1.html#pstring-ip-pointer" title="collect-skip">pstring-ip-pointer</a> <a class="applied-name" href="collect-skip-1.html#next-write" title="collect-skip">next-write</a> <a class="applied-name" href="collect-skip-1.html#next-read" title="collect-skip">next-read</a> <a class="applied-name" href="collect-skip-1.html#look-ahead-length" title="collect-skip">look-ahead-length</a> <a class="applied-name" href="collect-skip-1.html#look-ahead-vector" title="collect-skip">look-ahead-vector</a> <a class="applied-name" href="collect-skip-1.html#end-of-file?" title="collect-skip">end-of-file?</a> <a class="applied-name" href="collect-skip-1.html#collection-buffer" title="collect-skip">collection-buffer</a> <a class="applied-name" href="collect-skip-1.html#buffer-length" title="collect-skip">buffer-length</a>)))

<a name="put-look-ahead-buffer"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(put-look-ahead-buffer look-ahead-buffer-alist)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="collect-skip-1.html#ip" title="collect-skip">ip</a> (<a class="schemedoc-name" href="../../../lib/man/general.html#get" title="Manual: general">get</a> 'ip look-ahead-buffer-alist))
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="collect-skip-1.html#pstring-ip-pointer" title="collect-skip">pstring-ip-pointer</a> (<a class="schemedoc-name" href="../../../lib/man/general.html#get" title="Manual: general">get</a> 'pstring-ip-pointer look-ahead-buffer-alist))
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="collect-skip-1.html#next-write" title="collect-skip">next-write</a> (<a class="schemedoc-name" href="../../../lib/man/general.html#get" title="Manual: general">get</a> 'next-write look-ahead-buffer-alist))
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="collect-skip-1.html#next-read" title="collect-skip">next-read</a> (<a class="schemedoc-name" href="../../../lib/man/general.html#get" title="Manual: general">get</a> 'next-read look-ahead-buffer-alist))
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="collect-skip-1.html#look-ahead-length" title="collect-skip">look-ahead-length</a> (<a class="schemedoc-name" href="../../../lib/man/general.html#get" title="Manual: general">get</a> 'look-ahead-length look-ahead-buffer-alist))
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="collect-skip-1.html#look-ahead-vector" title="collect-skip">look-ahead-vector</a> (<a class="schemedoc-name" href="../../../lib/man/general.html#get" title="Manual: general">get</a> 'look-ahead-vector look-ahead-buffer-alist))
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="collect-skip-1.html#end-of-file?" title="collect-skip">end-of-file?</a> (<a class="schemedoc-name" href="../../../lib/man/general.html#get" title="Manual: general">get</a> 'end-of-file? look-ahead-buffer-alist))
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="collect-skip-1.html#collection-buffer" title="collect-skip">collection-buffer</a> (<a class="schemedoc-name" href="../../../lib/man/general.html#get" title="Manual: general">get</a> 'collection-buffer look-ahead-buffer-alist))
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="collect-skip-1.html#buffer-length" title="collect-skip">buffer-length</a> (<a class="schemedoc-name" href="../../../lib/man/general.html#get" title="Manual: general">get</a> 'buffer-length look-ahead-buffer-alist))
)


<a name="peek-a-char"></a><div class="schemedoc-definition-comment">;; Peek a character from the input port, but queues it for subsequent reading
;; at "the peek end".
;; This function always reads one character via generic-read-char, and puts in into the "peek end" of the buffer.</div><a name="peek-a-char"></a><span><a href="../collect-skip.html#peek-a-char"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(peek-a-char)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">ch</span> (<a class="applied-name" href="collect-skip-1.html#generic-read-char" title="collect-skip">generic-read-char</a> <a class="applied-name" href="collect-skip-1.html#ip" title="collect-skip">ip</a>)))
     (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="applied-name" href="collect-skip-1.html#generic-eof-object?" title="collect-skip">generic-eof-object?</a> ch)
         (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX125" title="R5RS Scheme form">begin</a> 
            (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="collect-skip-1.html#end-of-file?" title="collect-skip">end-of-file?</a> #t)
            ch)
         (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX125" title="R5RS Scheme form">begin</a>
           (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX405" title="R5RS Scheme form">vector-set!</a> <a class="applied-name" href="collect-skip-1.html#look-ahead-vector" title="collect-skip">look-ahead-vector</a> <a class="applied-name" href="collect-skip-1.html#next-write" title="collect-skip">next-write</a> ch)
           (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="collect-skip-1.html#next-write" title="collect-skip">next-write</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> 1 <a class="applied-name" href="collect-skip-1.html#next-write" title="collect-skip">next-write</a>))
           (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="collect-skip-1.html#look-ahead-length" title="collect-skip">look-ahead-length</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> 1 <a class="applied-name" href="collect-skip-1.html#look-ahead-length" title="collect-skip">look-ahead-length</a>))
           (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX237" title="R5RS Scheme form">&gt;</a> <a class="applied-name" href="collect-skip-1.html#look-ahead-length" title="collect-skip">look-ahead-length</a> <a class="applied-name" href="collect-skip-1.html#max-look-ahead" title="collect-skip">max-look-ahead</a>) (error "Lookahead buffer capacity exceeded"))
           (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX239" title="R5RS Scheme form">&gt;=</a> <a class="applied-name" href="collect-skip-1.html#next-write" title="collect-skip">next-write</a> <a class="applied-name" href="collect-skip-1.html#max-look-ahead" title="collect-skip">max-look-ahead</a>) (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="collect-skip-1.html#next-write" title="collect-skip">next-write</a> 0))
           ch))))

<a name="peek-chars"></a><div class="schemedoc-definition-comment">;; Peeks n charcters, by n calls of peek-a-char. 
;; In other words, the buffer is extended with n characters read from the input stream.
;; .internal-references "relies on" "peek-a-char"</div><a name="peek-chars"></a><span><a href="../collect-skip.html#peek-chars"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(peek-chars n)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX237" title="R5RS Scheme form">&gt;</a> n 0)
          (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX125" title="R5RS Scheme form">begin</a>
            (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">ch</span> (<a class="applied-name" href="collect-skip-1.html#peek-a-char" title="collect-skip">peek-a-char</a>)))
              (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> (<a class="applied-name" href="collect-skip-1.html#generic-eof-object?" title="collect-skip">generic-eof-object?</a> ch)) (<a class="applied-name" href="collect-skip-1.html#peek-chars" title="collect-skip">peek-chars</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> n 1))))))
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX236" title="R5RS Scheme form">&lt;</a> n 0) (error "peek-chars: Called with negative argument"))))

<a name="read-a-char"></a><div class="schemedoc-definition-comment">;; Read from the the look ahead buffer. Only if this buffer is empty, read from the port.
;; Reads from "the read end" of the queue.
;; In case the buffer is non-empty, this procedure takes a character out of the buffer in the "read end".
;; In any case, it advances the implicit input pointer of the input stream.</div><a name="read-a-char"></a><span><a href="../collect-skip.html#read-a-char"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(read-a-char)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX237" title="R5RS Scheme form">&gt;</a> <a class="applied-name" href="collect-skip-1.html#look-ahead-length" title="collect-skip">look-ahead-length</a> 0)
      (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">ch</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX404" title="R5RS Scheme form">vector-ref</a> <a class="applied-name" href="collect-skip-1.html#look-ahead-vector" title="collect-skip">look-ahead-vector</a> <a class="applied-name" href="collect-skip-1.html#next-read" title="collect-skip">next-read</a>)))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="collect-skip-1.html#next-read" title="collect-skip">next-read</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> <a class="applied-name" href="collect-skip-1.html#next-read" title="collect-skip">next-read</a> 1))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="collect-skip-1.html#look-ahead-length" title="collect-skip">look-ahead-length</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> <a class="applied-name" href="collect-skip-1.html#look-ahead-length" title="collect-skip">look-ahead-length</a> 1))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX239" title="R5RS Scheme form">&gt;=</a> <a class="applied-name" href="collect-skip-1.html#next-read" title="collect-skip">next-read</a> <a class="applied-name" href="collect-skip-1.html#max-look-ahead" title="collect-skip">max-look-ahead</a>) (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="collect-skip-1.html#next-read" title="collect-skip">next-read</a> 0))
        ch)
      (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">ch</span> (<a class="applied-name" href="collect-skip-1.html#generic-read-char" title="collect-skip">generic-read-char</a> <a class="applied-name" href="collect-skip-1.html#ip" title="collect-skip">ip</a>)))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="applied-name" href="collect-skip-1.html#generic-eof-object?" title="collect-skip">generic-eof-object?</a> ch)
            (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="collect-skip-1.html#end-of-file?" title="collect-skip">end-of-file?</a> #t))
        ch)))
            

<a name="read-a-string"></a><div class="schemedoc-definition-comment">;; Read and return a string of length n by means of repeated activations of read-a-char.
;; Takes eof into account such that a string shorter than n can be returned.</div><a name="read-a-string"></a><span><a href="../collect-skip.html#read-a-string"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(read-a-string n)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">res</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX375" title="R5RS Scheme form">make-string</a> n #\space)))
    (<a class="applied-name" href="collect-skip-1.html#read-a-string-1" title="collect-skip">read-a-string-1</a> 0 n res)
    res))

<a name="read-a-string-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(read-a-string-1 i n str)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX239" title="R5RS Scheme form">&gt;=</a> i n) str)
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX125" title="R5RS Scheme form">begin</a>
                 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX380" title="R5RS Scheme form">string-set!</a> str i (<a class="applied-name" href="collect-skip-1.html#read-a-char" title="collect-skip">read-a-char</a>))
                 (<a class="applied-name" href="collect-skip-1.html#read-a-string-1" title="collect-skip">read-a-string-1</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> i 1) n str)))))

<a name="look-ahead-prefix"></a><div class="schemedoc-definition-comment">;; Return a string of length lgt from the "read end" of the buffer. A proper function.
;; .pre-condition lgt cannot be larger than the number of characters in the buffer.</div><a name="look-ahead-prefix"></a><span><a href="../collect-skip.html#look-ahead-prefix"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(look-ahead-prefix lgt)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX239" title="R5RS Scheme form">&gt;=</a> <a class="applied-name" href="collect-skip-1.html#look-ahead-length" title="collect-skip">look-ahead-length</a> lgt)
      (<a class="applied-name" href="collect-skip-1.html#look-ahead-prefix-1" title="collect-skip">look-ahead-prefix-1</a> 0 <a class="applied-name" href="collect-skip-1.html#next-read" title="collect-skip">next-read</a> lgt (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX375" title="R5RS Scheme form">make-string</a> lgt #\space))
      (error (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> "look-ahead-prefix: requires the look ahead to be in the queue, " (<a class="schemedoc-name" href="../../../lib/man/general.html#as-string" title="Manual: general">as-string</a> lgt) ))))

<a name="look-ahead-prefix-1"></a><span class="comment">; i is the index into the formed string.
; j is the index into the look-ahead queue
; lgt is the desired length of the extracted string
; res is the (tail recursive) result.</span><br /><a name="look-ahead-prefix-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(look-ahead-prefix-1 i j n res)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX239" title="R5RS Scheme form">&gt;=</a> i n)
      res
      (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX125" title="R5RS Scheme form">begin</a>
         (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX380" title="R5RS Scheme form">string-set!</a> res i (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX404" title="R5RS Scheme form">vector-ref</a> <a class="applied-name" href="collect-skip-1.html#look-ahead-vector" title="collect-skip">look-ahead-vector</a> j))
         (<a class="applied-name" href="collect-skip-1.html#look-ahead-prefix-1" title="collect-skip">look-ahead-prefix-1</a>
            (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> i 1)
            (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> j (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> <a class="applied-name" href="collect-skip-1.html#max-look-ahead" title="collect-skip">max-look-ahead</a> 1)) 0 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> j 1)) <span class="comment">; <span><a name="look-ahead-prefix-1-@f"></a> @f</span></span><br />            n
            res))))

<a name="max-look-ahead-prefix"></a><div class="schemedoc-definition-comment">;; Return the entire look ahead queue as a string. A proper function.</div><a name="max-look-ahead-prefix"></a><span><a href="../collect-skip.html#max-look-ahead-prefix"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(max-look-ahead-prefix)</span>
  (<a class="applied-name" href="collect-skip-1.html#look-ahead-prefix" title="collect-skip">look-ahead-prefix</a> <a class="applied-name" href="collect-skip-1.html#look-ahead-length" title="collect-skip">look-ahead-length</a>))

<a name="look-ahead-char"></a><div class="schemedoc-definition-comment">;; Return the first character from the "read end" of the buffer. A proper function.
;; .pre-condition The buffer is not empty.</div><a name="look-ahead-char"></a><span><a href="../collect-skip.html#look-ahead-char"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(look-ahead-char)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX239" title="R5RS Scheme form">&gt;=</a> <a class="applied-name" href="collect-skip-1.html#look-ahead-length" title="collect-skip">look-ahead-length</a> 1)
      (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX404" title="R5RS Scheme form">vector-ref</a> <a class="applied-name" href="collect-skip-1.html#look-ahead-vector" title="collect-skip">look-ahead-vector</a> <a class="applied-name" href="collect-skip-1.html#next-read" title="collect-skip">next-read</a>)
      (error "look-ahead-char: Cannot look ahead in emtpy look ahead queue")))
  
<a name="match-look-ahead?"></a><div class="schemedoc-definition-comment">;; Return whether the buffer matches the string str. Matching is done by the function equal? A proper function.</div><a name="match-look-ahead?"></a><span><a href="../collect-skip.html#match-look-ahead?"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(match-look-ahead? str)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX122" title="R5RS Scheme form">let*</a> ((<span class="local-name-binding">lgt</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> str)))
    (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX239" title="R5RS Scheme form">&gt;=</a> <a class="applied-name" href="collect-skip-1.html#look-ahead-length" title="collect-skip">look-ahead-length</a> lgt)
        (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX200" title="R5RS Scheme form">equal?</a> (<a class="applied-name" href="collect-skip-1.html#look-ahead-prefix" title="collect-skip">look-ahead-prefix</a> lgt) str)
        #f)))

<a name="ensure-look-ahead"></a><div class="schemedoc-definition-comment">;; Make sure that there is at least n characters in the buffer.
;; If there are less than n characters, ented a sufficient number of characters with peek-chars.
;; .internal-references "relies on" "peek-chars"</div><a name="ensure-look-ahead"></a><span><a href="../collect-skip.html#ensure-look-ahead"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(ensure-look-ahead n)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX236" title="R5RS Scheme form">&lt;</a> <a class="applied-name" href="collect-skip-1.html#look-ahead-length" title="collect-skip">look-ahead-length</a> n)
      (<a class="applied-name" href="collect-skip-1.html#peek-chars" title="collect-skip">peek-chars</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> n <a class="applied-name" href="collect-skip-1.html#look-ahead-length" title="collect-skip">look-ahead-length</a>))))

<span class="comment">; ----------------------------------------------------------------------------
; Put back facility at the write end. Part of the look ahead queue.
; Alternatively - and more useful - put back should take place at the read end.</span><br />
<a name="put-back-a-char-write-end"></a><div class="schemedoc-definition-comment">;; Put ch into the "peek end" of buffer (where peek-a-char operates).</div><a name="put-back-a-char-write-end"></a><span><a href="../collect-skip.html#put-back-a-char-write-end"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(put-back-a-char-write-end ch)</span>
  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX405" title="R5RS Scheme form">vector-set!</a> <a class="applied-name" href="collect-skip-1.html#look-ahead-vector" title="collect-skip">look-ahead-vector</a> <a class="applied-name" href="collect-skip-1.html#next-write" title="collect-skip">next-write</a> ch)
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="collect-skip-1.html#next-write" title="collect-skip">next-write</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> 1 <a class="applied-name" href="collect-skip-1.html#next-write" title="collect-skip">next-write</a>))
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="collect-skip-1.html#look-ahead-length" title="collect-skip">look-ahead-length</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> 1 <a class="applied-name" href="collect-skip-1.html#look-ahead-length" title="collect-skip">look-ahead-length</a>))
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX237" title="R5RS Scheme form">&gt;</a> <a class="applied-name" href="collect-skip-1.html#look-ahead-length" title="collect-skip">look-ahead-length</a> <a class="applied-name" href="collect-skip-1.html#max-look-ahead" title="collect-skip">max-look-ahead</a>) (error "Lookahead buffer capacity exceeded"))
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX239" title="R5RS Scheme form">&gt;=</a> <a class="applied-name" href="collect-skip-1.html#next-write" title="collect-skip">next-write</a> <a class="applied-name" href="collect-skip-1.html#max-look-ahead" title="collect-skip">max-look-ahead</a>) (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="collect-skip-1.html#next-write" title="collect-skip">next-write</a> 0)))

<a name="put-back-a-char-read-end"></a><div class="schemedoc-definition-comment">;; Put ch into the "read end" buffer (where read-a-char operates).</div><a name="put-back-a-char-read-end"></a><span><a href="../collect-skip.html#put-back-a-char-read-end"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(put-back-a-char-read-end ch)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX238" title="R5RS Scheme form">&lt;=</a> <a class="applied-name" href="collect-skip-1.html#next-read" title="collect-skip">next-read</a> 0) (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="collect-skip-1.html#next-read" title="collect-skip">next-read</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> <a class="applied-name" href="collect-skip-1.html#max-look-ahead" title="collect-skip">max-look-ahead</a> 1)))
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="collect-skip-1.html#look-ahead-length" title="collect-skip">look-ahead-length</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> <a class="applied-name" href="collect-skip-1.html#look-ahead-length" title="collect-skip">look-ahead-length</a> 1))
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX239" title="R5RS Scheme form">&gt;=</a> <a class="applied-name" href="collect-skip-1.html#look-ahead-length" title="collect-skip">look-ahead-length</a> <a class="applied-name" href="collect-skip-1.html#max-look-ahead" title="collect-skip">max-look-ahead</a>) (error "Lookahead buffer capacity exceeded"))
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="collect-skip-1.html#next-read" title="collect-skip">next-read</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> <a class="applied-name" href="collect-skip-1.html#next-read" title="collect-skip">next-read</a> 1))
  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX405" title="R5RS Scheme form">vector-set!</a> <a class="applied-name" href="collect-skip-1.html#look-ahead-vector" title="collect-skip">look-ahead-vector</a> <a class="applied-name" href="collect-skip-1.html#next-read" title="collect-skip">next-read</a> ch))

<a name="put-back-a-string"></a><div class="schemedoc-definition-comment">;; Put str back into the buffer. The second parameter which-end controls whether to put back
;; in read end or write end (equivalent to peek end). Possible values of which end are the symbols read-end or write-end.</div><a name="put-back-a-string"></a><span><a href="../collect-skip.html#put-back-a-string"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(put-back-a-string str which-end)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> 0 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> str)) 'nothing)
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX199" title="R5RS Scheme form">eq?</a> which-end 'write-end) 
           (<a class="applied-name" href="collect-skip-1.html#put-back-a-string-write-end" title="collect-skip">put-back-a-string-write-end</a> str 0 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> str) 1)))
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX199" title="R5RS Scheme form">eq?</a> which-end 'read-end)
           (<a class="applied-name" href="collect-skip-1.html#put-back-a-string-read-end" title="collect-skip">put-back-a-string-read-end</a> str 0 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> str) 1)))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (error "put-back-a-string: Unknown end indicator"))))

<a name="put-back-a-string-write-end"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(put-back-a-string-write-end str i max)</span>
  (<a class="applied-name" href="collect-skip-1.html#put-back-a-char-write-end" title="collect-skip">put-back-a-char-write-end</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> str i))
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX236" title="R5RS Scheme form">&lt;</a> i max)
      (<a class="applied-name" href="collect-skip-1.html#put-back-a-string-write-end" title="collect-skip">put-back-a-string-write-end</a> str (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> i 1) max)))

<a name="put-back-a-string-read-end"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(put-back-a-string-read-end str min i)</span>
  (<a class="applied-name" href="collect-skip-1.html#put-back-a-char-read-end" title="collect-skip">put-back-a-char-read-end</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> str i))
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX237" title="R5RS Scheme form">&gt;</a> i min)
      (<a class="applied-name" href="collect-skip-1.html#put-back-a-string-read-end" title="collect-skip">put-back-a-string-read-end</a> str min (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> i 1))))


<a name="advance-look-ahead"></a><div class="schemedoc-definition-comment">;; Provided that there is at least n characters in the buffer, advance
;; next-read with n positions. Hereby n queued characters are skipped from the buffer at the "read end".</div><a name="advance-look-ahead"></a><span><a href="../collect-skip.html#advance-look-ahead"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(advance-look-ahead n)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX237" title="R5RS Scheme form">&gt;</a> n <a class="applied-name" href="collect-skip-1.html#look-ahead-length" title="collect-skip">look-ahead-length</a>) (error (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> "Cannot advance the look ahead with " (<a class="schemedoc-name" href="../../../lib/man/general.html#as-string" title="Manual: general">as-string</a> n) " positions")))
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX237" title="R5RS Scheme form">&gt;</a> n 0)
      (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX125" title="R5RS Scheme form">begin</a>
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="collect-skip-1.html#next-read" title="collect-skip">next-read</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> <a class="applied-name" href="collect-skip-1.html#next-read" title="collect-skip">next-read</a> 1))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="collect-skip-1.html#look-ahead-length" title="collect-skip">look-ahead-length</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> <a class="applied-name" href="collect-skip-1.html#look-ahead-length" title="collect-skip">look-ahead-length</a> 1))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX239" title="R5RS Scheme form">&gt;=</a> <a class="applied-name" href="collect-skip-1.html#next-read" title="collect-skip">next-read</a> <a class="applied-name" href="collect-skip-1.html#max-look-ahead" title="collect-skip">max-look-ahead</a>) (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="collect-skip-1.html#next-read" title="collect-skip">next-read</a> 0))
        (<a class="applied-name" href="collect-skip-1.html#advance-look-ahead" title="collect-skip">advance-look-ahead</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> n 1)))))

<span class="comment">; End of look ahead buffer (queue)</span><br />
<span class="comment">; -----------------------------------------------------</span><br /><a name="buffer-length"></a><div class="schemedoc-section-comment">;;; Collection and skipping functions.
;;; This section contains a number of higher level collection and skipping functions.
;;; These functions use the funtions from the previous section. The functions in this
;;; section are the most important of this library.</div>
<a name="buffer-length"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">buffer-length</span> 10000)
<a name="collection-buffer"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">collection-buffer</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX375" title="R5RS Scheme form">make-string</a> <a class="applied-name" href="collect-skip-1.html#buffer-length" title="collect-skip">buffer-length</a> #\space))

<a name="collect-until"></a><div class="schemedoc-definition-comment">;; Read and collect a string from the input, controlled by a predicate.
;; The collection stops when the predicate p holds on the character read.
;; The last read character (the first character on which p holds) is left as the oldest character in the queue.</div><a name="collect-until"></a><span><a href="../collect-skip.html#collect-until"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(collect-until p)</span>
  (<a class="applied-name" href="collect-skip-1.html#collect-until-1" title="collect-skip">collect-until-1</a> p <a class="applied-name" href="collect-skip-1.html#ip" title="collect-skip">ip</a> <a class="applied-name" href="collect-skip-1.html#collection-buffer" title="collect-skip">collection-buffer</a> 0)
)

<a name="collect-until-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(collect-until-1 p ip buffer next)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX239" title="R5RS Scheme form">&gt;=</a> next <a class="applied-name" href="collect-skip-1.html#buffer-length" title="collect-skip">buffer-length</a>) (error "collect-until-1: Collection buffer is filled. You can enlarge it via the variable buffer-length"))
        ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX237" title="R5RS Scheme form">&gt;</a> <a class="applied-name" href="collect-skip-1.html#look-ahead-length" title="collect-skip">look-ahead-length</a> 0) (p (<a class="schemedoc-name" href="../../../lib/man/general.html#as-char" title="Manual: general">as-char</a> (<a class="applied-name" href="collect-skip-1.html#look-ahead-prefix" title="collect-skip">look-ahead-prefix</a> 1))))
            (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> buffer 0 next))
        ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX237" title="R5RS Scheme form">&gt;</a> <a class="applied-name" href="collect-skip-1.html#look-ahead-length" title="collect-skip">look-ahead-length</a> 0) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> (p (<a class="schemedoc-name" href="../../../lib/man/general.html#as-char" title="Manual: general">as-char</a> (<a class="applied-name" href="collect-skip-1.html#look-ahead-prefix" title="collect-skip">look-ahead-prefix</a> 1)))))
          (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">ch</span> (<a class="applied-name" href="collect-skip-1.html#read-a-char" title="collect-skip">read-a-char</a>)))
             (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX380" title="R5RS Scheme form">string-set!</a> buffer next ch)
             (<a class="applied-name" href="collect-skip-1.html#collect-until-1" title="collect-skip">collect-until-1</a> p ip buffer (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> 1 next))))
        ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> <a class="applied-name" href="collect-skip-1.html#look-ahead-length" title="collect-skip">look-ahead-length</a> 0))
          (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">ch</span> (<a class="applied-name" href="collect-skip-1.html#peek-a-char" title="collect-skip">peek-a-char</a>)))
            (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (p ch)
                (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> buffer 0 next)
                (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX125" title="R5RS Scheme form">begin</a>
                  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX380" title="R5RS Scheme form">string-set!</a> buffer next ch)
                  (<a class="applied-name" href="collect-skip-1.html#read-a-char" title="collect-skip">read-a-char</a>)
                  (<a class="applied-name" href="collect-skip-1.html#collect-until-1" title="collect-skip">collect-until-1</a> p ip buffer (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> 1 next))))))))

<a name="collect-balanced-until"></a><div class="schemedoc-definition-comment">;; This collection procedure returns a balanced collection given two char predicates.
;; Return the string collected from the input port ip. The collection stops when the predicate char-pred-2 holds on the character read.
;; However, if char-pred-1 becomes true it has to be matched by char-pred-2 without causing a termination of the collection.
;; The last read character (the first character on which char-pred-2 holds) is processed by this function.
;; As a precondition assume that if char-pred-1 holds then char-pred-2 does not hold, and vice versa.</div><a name="collect-balanced-until"></a><span><a href="../collect-skip.html#collect-balanced-until"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(collect-balanced-until char-pred-1 char-pred-2)</span>
  (<a class="applied-name" href="collect-skip-1.html#collect-balanced-until-1" title="collect-skip">collect-balanced-until-1</a> char-pred-1 char-pred-2 <a class="applied-name" href="collect-skip-1.html#ip" title="collect-skip">ip</a> <a class="applied-name" href="collect-skip-1.html#collection-buffer" title="collect-skip">collection-buffer</a> 0 0))

<a name="collect-balanced-until-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(collect-balanced-until-1 q p ip buffer next bal-count)</span>
  (<a class="applied-name" href="collect-skip-1.html#ensure-look-ahead" title="collect-skip">ensure-look-ahead</a> 1)
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX239" title="R5RS Scheme form">&gt;=</a> next <a class="applied-name" href="collect-skip-1.html#buffer-length" title="collect-skip">buffer-length</a>) (parse-error "collect-until-1: Collection buffer is filled. You can enlarge it via the variable buffer-length"))
        ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (p (<a class="schemedoc-name" href="../../../lib/man/general.html#as-char" title="Manual: general">as-char</a> (<a class="applied-name" href="collect-skip-1.html#look-ahead-prefix" title="collect-skip">look-ahead-prefix</a> 1))) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> bal-count 0))
            (parse-error "End delimitor matched before start delimitor"))
        ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (p (<a class="schemedoc-name" href="../../../lib/man/general.html#as-char" title="Manual: general">as-char</a> (<a class="applied-name" href="collect-skip-1.html#look-ahead-prefix" title="collect-skip">look-ahead-prefix</a> 1))) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> bal-count 1))
            (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX380" title="R5RS Scheme form">string-set!</a> buffer next (<a class="applied-name" href="collect-skip-1.html#read-a-char" title="collect-skip">read-a-char</a>))
            (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> buffer 0 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> next 1)))
        ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (p (<a class="schemedoc-name" href="../../../lib/man/general.html#as-char" title="Manual: general">as-char</a> (<a class="applied-name" href="collect-skip-1.html#look-ahead-prefix" title="collect-skip">look-ahead-prefix</a> 1))) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX237" title="R5RS Scheme form">&gt;</a> bal-count 1))
          (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">ch</span> (<a class="applied-name" href="collect-skip-1.html#read-a-char" title="collect-skip">read-a-char</a>)))
             (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX380" title="R5RS Scheme form">string-set!</a> buffer next ch)
             (<a class="applied-name" href="collect-skip-1.html#collect-balanced-until-1" title="collect-skip">collect-balanced-until-1</a> q p ip buffer (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> 1 next) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> bal-count 1))))
        ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (q (<a class="schemedoc-name" href="../../../lib/man/general.html#as-char" title="Manual: general">as-char</a> (<a class="applied-name" href="collect-skip-1.html#look-ahead-prefix" title="collect-skip">look-ahead-prefix</a> 1))))
          (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">ch</span> (<a class="applied-name" href="collect-skip-1.html#read-a-char" title="collect-skip">read-a-char</a>)))
             (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX380" title="R5RS Scheme form">string-set!</a> buffer next ch)
             (<a class="applied-name" href="collect-skip-1.html#collect-balanced-until-1" title="collect-skip">collect-balanced-until-1</a> q p ip buffer (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> 1 next) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> bal-count 1))))
        ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> (p (<a class="schemedoc-name" href="../../../lib/man/general.html#as-char" title="Manual: general">as-char</a> (<a class="applied-name" href="collect-skip-1.html#look-ahead-prefix" title="collect-skip">look-ahead-prefix</a> 1)))) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> (q (<a class="schemedoc-name" href="../../../lib/man/general.html#as-char" title="Manual: general">as-char</a> (<a class="applied-name" href="collect-skip-1.html#look-ahead-prefix" title="collect-skip">look-ahead-prefix</a> 1)))))
          (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">ch</span> (<a class="applied-name" href="collect-skip-1.html#read-a-char" title="collect-skip">read-a-char</a>)))
             (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX380" title="R5RS Scheme form">string-set!</a> buffer next ch)
             (<a class="applied-name" href="collect-skip-1.html#collect-balanced-until-1" title="collect-skip">collect-balanced-until-1</a> q p ip buffer (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> 1 next) bal-count)))))



<a name="skip-while"></a><div class="schemedoc-definition-comment">;; Skip characters while p holds.
;; The first character on which p fails is left as the oldest character in the queue.
;; The predicate does not hold if end of file.</div><a name="skip-while"></a><span><a href="../collect-skip.html#skip-while"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(skip-while p)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> <a class="applied-name" href="collect-skip-1.html#end-of-file?" title="collect-skip">end-of-file?</a>) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX237" title="R5RS Scheme form">&gt;</a> <a class="applied-name" href="collect-skip-1.html#look-ahead-length" title="collect-skip">look-ahead-length</a> 0) (p (<a class="schemedoc-name" href="../../../lib/man/general.html#as-char" title="Manual: general">as-char</a> (<a class="applied-name" href="collect-skip-1.html#look-ahead-prefix" title="collect-skip">look-ahead-prefix</a> 1)))) 
            (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX125" title="R5RS Scheme form">begin</a> (<a class="applied-name" href="collect-skip-1.html#read-a-char" title="collect-skip">read-a-char</a>) (<a class="applied-name" href="collect-skip-1.html#skip-while" title="collect-skip">skip-while</a> p)))
        ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> <a class="applied-name" href="collect-skip-1.html#end-of-file?" title="collect-skip">end-of-file?</a>) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> <a class="applied-name" href="collect-skip-1.html#look-ahead-length" title="collect-skip">look-ahead-length</a> 0))
            (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX125" title="R5RS Scheme form">begin</a> (<a class="applied-name" href="collect-skip-1.html#peek-a-char" title="collect-skip">peek-a-char</a>)
                   (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> <a class="applied-name" href="collect-skip-1.html#end-of-file?" title="collect-skip">end-of-file?</a>) (p (<a class="schemedoc-name" href="../../../lib/man/general.html#as-char" title="Manual: general">as-char</a> (<a class="applied-name" href="collect-skip-1.html#look-ahead-prefix" title="collect-skip">look-ahead-prefix</a> 1))))
                       (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX125" title="R5RS Scheme form">begin</a> (<a class="applied-name" href="collect-skip-1.html#read-a-char" title="collect-skip">read-a-char</a>) (<a class="applied-name" href="collect-skip-1.html#skip-while" title="collect-skip">skip-while</a> p)))))))
         
<a name="skip-string"></a><div class="schemedoc-definition-comment">;; Assume that str is just in front of us. Skip through it.
;; If str is not in front of us, a fatal error occurs with if-not-message as error message.</div><a name="skip-string"></a><span><a href="../collect-skip.html#skip-string"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(skip-string str if-not-message)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">str-1</span> (<a class="applied-name" href="collect-skip-1.html#read-a-string" title="collect-skip">read-a-string</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> str))))
    (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX200" title="R5RS Scheme form">equal?</a> str str-1))
        (error if-not-message))))


<a name="skip-until-string"></a><div class="schemedoc-definition-comment">;; Skip characters until str is encountered. If inclusive, also skip str.
;; It is assumed as a precondition that the length of str is at least one.</div><a name="skip-until-string"></a><span><a href="../collect-skip.html#skip-until-string"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(skip-until-string str . inclusive)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX122" title="R5RS Scheme form">let*</a> ((<span class="local-name-binding">str-lgt</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> str))
         (<span class="local-name-binding">first-ch</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> str 0))
         (<span class="local-name-binding">incl</span> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> inclusive) #f (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> inclusive))))
    (<a class="applied-name" href="collect-skip-1.html#skip-until-string-1" title="collect-skip">skip-until-string-1</a> str str-lgt first-ch incl)))

<a name="skip-until-string-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(skip-until-string-1 str str-lgt first-ch incl)</span>
  (<a class="applied-name" href="collect-skip-1.html#skip-while" title="collect-skip">skip-while</a> (<a class="schemedoc-name" href="../../../lib/man/general.html#negate" title="Manual: general">negate</a> (<a class="applied-name" href="collect-skip-1.html#char-predicate" title="collect-skip">char-predicate</a> first-ch)))
  (<a class="applied-name" href="collect-skip-1.html#ensure-look-ahead" title="collect-skip">ensure-look-ahead</a> str-lgt)
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX200" title="R5RS Scheme form">equal?</a> (<a class="applied-name" href="collect-skip-1.html#look-ahead-prefix" title="collect-skip">look-ahead-prefix</a> str-lgt) str)
      (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> incl (<a class="applied-name" href="collect-skip-1.html#read-a-string" title="collect-skip">read-a-string</a> str-lgt))
      (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX125" title="R5RS Scheme form">begin</a> 
         (<a class="applied-name" href="collect-skip-1.html#read-a-char" title="collect-skip">read-a-char</a>) <span class="comment">; eat the matched first char</span><br />         (<a class="applied-name" href="collect-skip-1.html#skip-until-string-1" title="collect-skip">skip-until-string-1</a> str str-lgt first-ch incl))))


<a name="collect-until-string"></a><div class="schemedoc-definition-comment">;; Collect characters until str is encountered. If inclusive, also collect str.
;; It is assumed as a precondition that the length of str is at least one.</div><a name="collect-until-string"></a><span><a href="../collect-skip.html#collect-until-string"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(collect-until-string str . inclusive)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX122" title="R5RS Scheme form">let*</a> ((<span class="local-name-binding">str-lgt</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> str))
         (<span class="local-name-binding">first-ch</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> str 0))
         (<span class="local-name-binding">incl</span> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> inclusive) #f (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> inclusive))))
    (<a class="applied-name" href="collect-skip-1.html#collect-until-string-1" title="collect-skip">collect-until-string-1</a> str str-lgt first-ch incl)))

<a name="collect-until-string-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(collect-until-string-1 str str-lgt first-ch incl)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">res</span> (<a class="applied-name" href="collect-skip-1.html#collect-until" title="collect-skip">collect-until</a> (<a class="applied-name" href="collect-skip-1.html#char-predicate" title="collect-skip">char-predicate</a> first-ch))))
    (<a class="applied-name" href="collect-skip-1.html#ensure-look-ahead" title="collect-skip">ensure-look-ahead</a> str-lgt)
    (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX200" title="R5RS Scheme form">equal?</a> (<a class="applied-name" href="collect-skip-1.html#look-ahead-prefix" title="collect-skip">look-ahead-prefix</a> str-lgt) str)
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> incl (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> res (<a class="applied-name" href="collect-skip-1.html#read-a-string" title="collect-skip">read-a-string</a> str-lgt)) res)
        (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> res (<a class="schemedoc-name" href="../../../lib/man/general.html#as-string" title="Manual: general">as-string</a> (<a class="applied-name" href="collect-skip-1.html#read-a-char" title="collect-skip">read-a-char</a>)) (<a class="applied-name" href="collect-skip-1.html#collect-until-string-1" title="collect-skip">collect-until-string-1</a> str str-lgt first-ch incl)))))



<span class="comment">; ----------------------------------------------</span><br /><div class="schemedoc-section-comment">;;; Useful predicates for skipping and collecting.</div>
<a name="is-white-space?"></a><div class="schemedoc-definition-comment">;; Is ch a white space character?</div><a name="is-white-space?"></a><span><a href="../collect-skip.html#is-white-space?"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(is-white-space? ch)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="applied-name" href="collect-skip-1.html#eof?" title="collect-skip">eof?</a> ch) 
      #f
      (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">n</span> (<a class="schemedoc-name" href="../../../lib/man/general.html#as-number" title="Manual: general">as-number</a> ch)))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX118" title="R5RS Scheme form">or</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX196" title="R5RS Scheme form">eqv?</a> n 32) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX196" title="R5RS Scheme form">eqv?</a> n 9) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX196" title="R5RS Scheme form">eqv?</a> n 10) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX196" title="R5RS Scheme form">eqv?</a> n 12) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX196" title="R5RS Scheme form">eqv?</a> n 13)))))

<a name="end-of-line?"></a><div class="schemedoc-definition-comment">;; Is ch an end of line charcter?</div><a name="end-of-line?"></a><span><a href="../collect-skip.html#end-of-line?"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(end-of-line? ch)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="applied-name" href="collect-skip-1.html#eof?" title="collect-skip">eof?</a> ch) 
      #f
      (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">n</span> (<a class="schemedoc-name" href="../../../lib/man/general.html#as-number" title="Manual: general">as-number</a> ch)))
         (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX118" title="R5RS Scheme form">or</a>  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX196" title="R5RS Scheme form">eqv?</a> n 10) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX196" title="R5RS Scheme form">eqv?</a> n 13)))))

<a name="eof?"></a><div class="schemedoc-definition-comment">;; Is ch an end of file character?</div><a name="eof?"></a><span><a href="../collect-skip.html#eof?"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(eof? ch)</span>
  (<a class="applied-name" href="collect-skip-1.html#generic-eof-object?" title="collect-skip">generic-eof-object?</a> ch))

<a name="char-predicate"></a><div class="schemedoc-definition-comment">;; Return a predicate functions which matches the character ch.
;; A higher order function.</div><a name="char-predicate"></a><span><a href="../collect-skip.html#char-predicate"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(char-predicate ch)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX98" title="R5RS Scheme form">lambda</a> (<span class="local-name-binding">c</span>) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX196" title="R5RS Scheme form">eqv?</a> c ch)))

</pre></font><div>&nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p></div></body></html>